Option Strict Off
Option Explicit On
Friend Class frmUtilities2
	Inherits System.Windows.Forms.Form
	
	'Declare APIs that enable you to search for a directory name
	'UPGRADE_WARNING: Structure BrowseInfo may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
	Private Declare Function SHBrowseForFolder Lib "shell32" (ByRef lpBI As BrowseInfo) As Integer
	Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Integer, ByVal lpBuffer As String) As Integer
	Private Declare Function lstrcat Lib "kernel32"  Alias "lstrcatA"(ByVal lpString1 As String, ByVal lpString2 As String) As Integer
	
	Private Structure BrowseInfo
		Dim hWndOwner As Integer
		Dim pIDLRoot As Integer
		Dim pszDisplayName As Integer
		Dim lpszTitle As Integer
		Dim ulFlags As Integer
		Dim lpfnCallback As Integer
		Dim lParam As Integer
		Dim iImage As Integer
	End Structure
	
	Dim FunctionChosen As String 'The current function chosen by the user
	
	
	
	Private Sub frmUtilities2_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		
		'UPGRADE_NOTE: The Following line was commented to give the same effect as VB6. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="1C44C272-DA6E-4A2A-BDC5-9A27F0D03D31"'
		'Me.FormBorderStyle = 0
		'UPGRADE_ISSUE: Form property frmUtilities2.ScaleMode is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8027179A-CB3B-45C0-9863-FAA1AF983B59"'
        'frmUtilities2.ScaleMode = 3 'Set scalemode to pixels
		Me.Width = VB6.TwipsToPixelsX(960 * VB6.TwipsPerPixelX)
		Me.Height = VB6.TwipsToPixelsY(710 * VB6.TwipsPerPixelY)
		Me.Left = VB6.TwipsToPixelsX((VB6.PixelsToTwipsX(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) / 2) - ((960 * VB6.TwipsPerPixelX) / 2)) 'Set the window to be in the middle of the screen
		Me.Top = VB6.TwipsToPixelsY((VB6.PixelsToTwipsY(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) / 2) - (((710 / 2) + 28) * VB6.TwipsPerPixelY)) 'Set the window raised up slightly. So it is better positioned when running at 1024 x 768
		
		'UPGRADE_ISSUE: PictureBox property picFacia3.ScaleMode was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
        'picFacia3.ScaleMode = 3
		'UPGRADE_ISSUE: PictureBox property picFacia3.AutoSize was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		picFacia3.AutoSize = True : picFacia3.Left = 0 : picFacia3.Top = 0
		'UPGRADE_ISSUE: PictureBox property picFacia3.AutoRedraw was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
        'picFacia3.AutoRedraw = True : picFacia3.BorderStyle = System.Windows.Forms.BorderStyle.None
		picFacia3.Visible = True
		picFacia3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
		'UPGRADE_WARNING: Picture has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		picFacia3.BackgroundImage = System.Drawing.Image.FromFile(My.Application.Info.DirectoryPath & "\Skins\" & Skin & "_Settings_S.jpg") 'Setup the correct picture. The utilities window uses the same skin as the settings window
		
		'UPGRADE_WARNING: Control property picFacia3.Parent was upgraded to picFacia3.FindForm which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
		SetWindowRgn(picFacia3.FindForm.Handle.ToInt32, RegionUtilities, True) 'Set the region of the Utilities box outside which nothing will be displayed. The region has been
		UtilityFPS = FPS 'Set the FPS on this form to that of the main program
		Me.cmdFPS.Text = UtilityFPS & " Frames per Second" 'Set the button which shows the current frames per second
		Call InformUser(1) 'Ask user to select an option
	End Sub
	
	Private Sub picFacia3_MouseUp(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles picFacia3.MouseUp
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = eventArgs.X
		Dim Y As Single = eventArgs.Y 'Mouse button has been released over picturebox (skin of form)
		If ActiveWindowIs <> "UtilitiesWindow" Then Exit Sub 'If the editor window is not active, dont action any buttons
		
		If Button = VB6.MouseButtonConstants.LeftButton Then 'The mouse button is the left button
			Red = 0 : Green = 0 : Blue = 0 'Reset the rgb values
			Call GetCursorPos(MousePoint) 'Get the screen position of the cursor
			Call ScreenToClient(Me.picFacia3.Handle.ToInt32, MousePoint) 'Modify values so they are relative to top left of settings window
			PixCol = GetPixel(Hotspot_Settings, MousePoint.X, MousePoint.Y) 'Get the relative colour at the mouse point of the hotspot image in memory
			Red = PixCol And &HFF : Green = CShort(PixCol And &HFF00) / 256 : Blue = CShort(PixCol And &HFF0000) / 65535 'Get the value of each color byte (rgb)
			If Red = 85 And Green = 129 And Blue = 9 Then
				ErrorCodeNo = "00.00" 'Tell the program it is a normal exit
				Call ExitProgram() 'You have released the quit button on the settings form
			End If
			If Red = 206 And Green = 185 And Blue = 245 Then Call LeaveUtilities() 'You have released the Continue Button on the utilities form
		End If
	End Sub
	Private Sub LeaveUtilities()
		ActiveWindowIs = "ButtonWindow" 'Make Buttons window active again so buttons and hotkeys will now work again
		Me.Visible = False 'Hide the Utilities form
	End Sub
	Private Sub cmdChangeFPS_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdChangeFPS.Click
		FunctionChosen = "FPS"
		Call DisableButtons() 'Initially disable all buttons and set them all to blue
		cmdChangeFPS.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the selected option button to red
		Call InformUser(2) 'Ask user to fill in fields and hit go
		
		
		'Now begin to enable the buttons that the user will require, in this case it is the source file and the frames per second button
		cmdSourceFile.Enabled = True 'Enable the button so the user can select the source file
		cmdSourceFile.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the source file button to red to show it is active
		cmdFPS.Enabled = True 'Enable the button so the user can choose the frames per second
		cmdFPS.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the frames per second button to red to show it is active
		cmdGo.Enabled = True 'Enable the go button
	End Sub
	
	Private Sub cmdJpegToMJpeg_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdJpegToMJpeg.Click
		FunctionChosen = "JPG>MJPG"
		Call DisableButtons() 'Initially disable all buttons and set them all to blue
		cmdJpegToMJpeg.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the selected option button to red
		Call InformUser(3) 'Ask user to fill in fields and hit go
		
		'Now begin to enable the buttons that the user will require, in this case it is the source file and the frames per second button
		cmdSourceDirectory.Enabled = True 'Enable the directory button
		cmdSourceDirectory.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the source directory button to red to show it is active
		cmdFPS.Enabled = True 'Enable the button so the user can choose the frames per second
		cmdFPS.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the frames per second button to red to show it is active
		cmdGo.Enabled = True 'Enable the go button
	End Sub
	
	
	Private Sub cmdExtractFrames_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExtractFrames.Click
		'*****************TO BE COMPLETED*********************
		FunctionChosen = "EXTRACTFRAMES"
		Call DisableButtons() 'Initially disable all buttons and set them all to blue
		cmdExtractFrames.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the selected option button to red
		Call InformUser(4) 'Ask user to fill in fields and hit go
		
		'Now begin to enable the buttons that the user will require
		cmdSourceFile.Enabled = True 'Enable the button so the user can select the source file
		cmdSourceFile.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the source file button to red to show it is active
		cmdGo.Enabled = True 'Enable the go button
	End Sub
	Private Sub cmdTranslatePgo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdTranslatePgo.Click 'Translates Papagayo files .pgo to Helium Frog phoneme sheets .txt
		FunctionChosen = "PGO>TXT"
		Call DisableButtons() 'Initially disable all buttons and set them all to blue
		cmdTranslatePgo.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the selected option button to red
		Call InformUser(11) 'Ask user to fill in fields and hit go
		
		'Now begin to enable the buttons that the user will require
		cmdSourceFile.Enabled = True 'Enable the button so the user can select the source file
		cmdSourceFile.BackColor = System.Drawing.ColorTranslator.FromOle(&H80) 'Change the source file button to red to show it is active
		cmdGo.Enabled = True 'Enable the go button
	End Sub
	Private Sub cmdFPS_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFPS.Click 'The button to allow the user to select a new frames per second
		frmFramePerSecond.Visible = True 'Show the form so user can select the frames per second
		frmFramePerSecond.Activate() 'Set focus on form. This enables user to bring form to the front if it is hidden using this button
	End Sub
	Private Sub cmdSourceFile_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSourceFile.Click
		If FunctionChosen = "PGO>TXT" Then
			'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			dlgInputFileOpen.Filter = "Animation File (*.pgo) | *.pgo" 'Set the common dialog box to only show .pgo files
		Else
			'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			dlgInputFileOpen.Filter = "Animation File (*.avi) | *.avi" 'Set the common dialog box to only show .avi files
		End If
		dlgInputFileOpen.ShowDialog() 'Open a dialog window so the user can select a filename
		If dlgInputFileOpen.FileName <> "" Then
			txtSourceFile.Text = dlgInputFileOpen.FileName 'Set the textbox to display the filename
		End If
	End Sub
	Private Sub cmdSourceDirectory_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSourceDirectory.Click
		frmDirectorySelect.Visible = True
		frmDirectorySelect.Activate() 'Set focus on form. This enables user to bring form to the front if it is hidden for any reason
	End Sub
	Private Sub cmdGo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGo.Click 'This is the main action button
		
		Me.List1.Items.Clear() 'Clear the report window
		
		'*********Change Frames per second**********************************
		If FunctionChosen = "FPS" Then
			If ChangeAviFrameRate((txtSourceFile.Text), UtilityFPS) = True Then 'Change the frame rate of the file.
				Call InformUser(7) 'FPS changed successfully  so inform the user
			Else
				Call InformUser(8) 'FPS not changed successfully  so inform the user
			End If
			Exit Sub
		End If
		
		'*********Concatenate a series of Jpegs to an AVI file**********************************
		If FunctionChosen = "JPG>MJPG" Then
			If ConcatJPG((txtSourceDirectory.Text), UtilityFPS) = True Then 'Call the ConcatenateJPG module
				Call InformUser(5) 'Concatenated successfully so inform the user
			Else
				Call InformUser(6) 'Concatenated unsuccessfully so inform the user
			End If
			Exit Sub
		End If
		
		'*********Extract individual frames from an AVI file**********************************
		If FunctionChosen = "EXTRACTFRAMES" Then
			If ExtractMultipleFrames((txtSourceFile.Text)) = True Then 'Call the ExtractMultipleFrames module
				Call InformUser(9) 'Extracted successfully so inform the user
			Else
				Call InformUser(10) 'Extracted unsuccessfully so inform the user
			End If
			Exit Sub
		End If
		
		'*********Convert a Papagayp .pgo file to a Helium Frog Phoneme .txt file**********************************
		If FunctionChosen = "PGO>TXT" Then
			If ConvertPapagayo((txtSourceFile.Text)) = True Then
				Call InformUser(12) 'Converted successfully so inform the user
			Else
				Call InformUser(13) 'Converted unsuccessfully so inform the user
			End If
			Beep()
			Exit Sub
		End If
		
		
		
		
	End Sub
	Private Sub DisableButtons()
		'This subroutine disables all buttons and returns them to Blue.
		
		cmdChangeFPS.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		cmdJpegToMJpeg.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		cmdExtractFrames.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		
		cmdSourceFile.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		cmdSourceFile.Enabled = False
		cmdSourceDirectory.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		cmdSourceDirectory.Enabled = False
		cmdFPS.BackColor = System.Drawing.ColorTranslator.FromOle(&HFFC8C8)
		cmdFPS.Enabled = False
		
		cmdGo.Enabled = False
	End Sub
	Private Sub InformUser(ByRef MessageType As Integer) 'Changes text in list box on form
		Select Case MessageType 'Depending on the value of MessageType variable take the following actions.
			Case Is = 1
				Me.List1.Items.Clear() 'Clear the list window
				Me.List1.Items.Add("Select the utility you require from the top menu below")
			Case Is = 2
				Me.List1.Items.Clear() 'Clear the list window
				Me.List1.Items.Add("Change Frames Per Second utility.                      Please complete active(Red) fields then hit Go button")
			Case Is = 3
				Me.List1.Items.Clear() 'Clear the list window
				Me.List1.Items.Add("Convert Jpeg Frames to Motion Jpeg file utility.       Please complete active(Red) fields then hit Go button")
			Case Is = 4
				Me.List1.Items.Clear() 'Clear the list window
				Me.List1.Items.Add("Extract frames from an AVI file utility.               Please complete active(Red) fields then hit Go button")
			Case Is = 5
				' frmUtilities2.List1.AddItem "Motion Jpeg file created successfully"
			Case Is = 6
				Me.List1.Items.Add("Motion Jpeg file not created") : Beep()
			Case Is = 7
				Me.List1.Items.Add("Frames per Second changed successfully to " & UtilityFPS & " frames per second")
			Case Is = 8
				'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
				If Dir(txtSourceFile.Text) = "" Then
					Me.List1.Items.Add("File does not exist or hasn't been specified by user.") : Beep() 'User hasn't selected a file
				End If
				If SavePath & ProjName & ".avi" = txtSourceFile.Text Then 'The file to change is the same as that in the animator
					Me.List1.Items.Add("You cannot edit a file that is currently being animated.") : Beep() 'Tell user the framerate has not been changed.
				End If
			Case Is = 9
				Me.List1.Items.Add("Frames extracted successfully")
			Case Is = 10
				Me.List1.Items.Add("Failed to extract frames") : Beep()
			Case Is = 11
				Me.List1.Items.Clear() 'Clear the list window
				Me.List1.Items.Add("Convert Papagayo .pgo file to a Helium Frog Phoneme .txt file. Please complete active(Red) fields then hit Go button  ")
			Case Is = 12
				Me.List1.Items.Add("Converted .pgo file successfully")
			Case Is = 13
				Me.List1.Items.Add("Failed convert .pgo file") : Beep()
				
				
				
				
				
		End Select
		'UPGRADE_ISSUE: ListBox property List1.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="F649E068-7137-45E5-AC20-4D80A3CC70AC"'
        Me.List1.SelectedIndex = Me.List1.Items.Count - 1 'Scroll listbox down to show last added item
	End Sub
End Class